/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2023-2023.
 * Description: rtos its enhance feature functions
 * Author: huyizhou
 * Create: 2023-09-14
 */

static int its_set_pri(struct irq_data *d, u8 prio)
{
	if (!d) {
		pr_err("[%s]%d irq data is NULL!\n", __func__, __LINE__);
		return -EINVAL;
	}

	if (prio < MIN_IRQ_PRI_NUM || prio >= DEFAULT_PMR_VALUE) {
		pr_err("[%s]%d prio %u out of restriction\n",
				__func__, __LINE__, prio);
		return -EINVAL;
	}

	lpi_update_config(d, LPI_PROP_PRIORITY_MASK,
				(prio & LPI_PROP_PRIORITY_MASK));

	return 0;
}

static int its_get_pri(struct irq_data *d, u8 *prio)
{
	irq_hw_number_t hwirq;
	void *va = NULL;
	u8 *cfg = NULL;

	if (!prio)
		return -EINVAL;

	if (!d) {
		pr_err("[%s]%d irq data is NULL!\n", __func__, __LINE__);
		return -EINVAL;
	}

	hwirq = d->irq;
	va = gic_rdists->prop_table_va;
	cfg = va + hwirq - MIN_LPI_NUM;
	*prio = ((*cfg) & LPI_PROP_PRIORITY_MASK);

	return 0;
}
